Every boxplot means a monitoring point (Ponto de monitoramento (or PM) in portuguese). My goal here is to analyze the evolution between decades of each water quality parameter that compounds the Water Quality Index (WQI).
The river flows in the east-west direction as shown in the image below.
The logic behind the sorting in the boxplots is because of 2 main reasons:
Some features that I want to add:
If the parameter is x, then use x’s classes (with its own classes background color plotted)
Define the timescale, should act just like a filter
# plan_wide_19902020 %>%
# filter(ano_coleta > "1990" &
# ano_coleta <= "2000")87398500, 87398980, 87398900, 87398950, 87405500, 87406900, 87409900
~facet.gridNamon tá com com casa decimal "," e
ptot tá com "."| 1990-2000 | 2000-2010 | 2010-2020 |
|---|---|---|
| 1990-2000 | 2000-2010 | 2010-2020 |
# install.packages(tidyverse)# library(ggpubr)
pacman::p_load(readr, rmarkdown, readxl, janitor,
pillar, dplyr, tidyverse,
# gapminder,
knitr, kableExtra, see,
gridExtra, #modelsummary,
gtsummary, ggplot2,
ggbeeswarm, GGally, ggtext, cowplot,
report)
# pacman::p_load(tibbletime)
# cite_packages()knitr::knit_hooks$set(time_it = local({
now <- NULL
function(before, options) {
if (before) {
# record the current time before each chunk
now <<- Sys.time()
} else {
# calculate the time difference after a chunk
res <- difftime(Sys.time(), now)
# return a character string to show the time
paste("Time for this code chunk to run:", res)
}
}
}))
knitr::opts_chunk$set(time_it = TRUE)# version$version.string
# citation(package = "tidyverse")Time for this code chunk to run: 0.00231504440307617
Time for this code chunk to run: 1.21519303321838
Time for this code chunk to run: 0.433634042739868
Como há dados faltantes, no cálculo entre o produto das colunas, o R
acaba interpretando como se fosse zero, mas na verdade é
NA.
plan_wide_19902020 <- plan_wide_19902020 %>%
mutate(iqa = ifelse(iqa == 0, NA, iqa))
parametros_IQA <- plan_wide_19902020 %>%
select(
codigo,
ponto_monitoramento,
pH,
oxigenio_dissolvido,
dbo,
fosforo_total,
escherichia_coli,
nitrogenio_amoniacal,
nitrogenio_kjeldahl,
nitrogenio_total,
turbidez,
temperatura_agua,
solidos_totais,
condutividade,
ano_coleta
)
write.csv(parametros_IQA,
"./parametros_IQA.csv",
row.names = FALSE)
plan_wide_19902020 %>%
select(starts_with("iqa_")) %>%
mutate(
teste_iqa_calc = prod() #queria tentar gerar o produtório entre as colunas que já possuem o IQA^2
)## # A tibble: 1,179 × 18
## iqa_dbo iqa_p…¹ iqa_n…² iqa_od iqa_pH iqa_t…³ iqa_c…⁴ iqa_s…⁵ iqa_o…⁶ iqa_t…⁷
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 54.0 72.7 89.0 84.6 89.8 61.9 76.6 83.9 2.13 1.58
## 2 54.0 78.0 87.6 90.9 87.7 61.9 47.2 84.7 2.15 1.58
## 3 29.0 38.3 59.3 76.2 82.9 80.2 60.4 79.4 2.09 1.58
## 4 69.1 77.4 93.7 89.7 77.0 58.7 63.0 85.8 2.15 1.58
## 5 69.1 71.7 88.8 97.5 89.8 63.1 49.7 83.3 2.18 1.58
## 6 78.1 91.2 94.0 89.9 85.4 65.7 57.1 86.1 2.15 1.58
## 7 61.0 63.4 90.4 79.6 82.9 73.6 47.2 86.1 2.10 1.58
## 8 69.1 67.8 89.4 74.4 85.4 59.7 69.8 73.7 2.08 1.58
## 9 61.0 54.3 83.2 76.6 73.6 65.7 63.0 86.0 2.09 1.58
## 10 78.1 78.0 89.6 86.1 92.0 58.7 56.0 83.7 2.13 1.58
## # … with 1,169 more rows, 8 more variables: iqa_coli_2 <dbl>, iqa_pH_2 <dbl>,
## # iqa_dbo_2 <dbl>, iqa_nitro_tot_2 <dbl>, iqa_ptot_2 <dbl>, iqa_turb_2 <dbl>,
## # iqa_sol_tot_2 <dbl>, teste_iqa_calc <dbl>, and abbreviated variable names
## # ¹iqa_ptot, ²iqa_nitro_tot, ³iqa_turb, ⁴iqa_coli, ⁵iqa_sol_tot, ⁶iqa_od_2,
## # ⁷iqa_temp_agua
Time for this code chunk to run: 0.362691164016724
Time for this code chunk to run: 0.00242090225219727
Time for this code chunk to run: 0.00496697425842285
theme_grafs <- function(bg = "white",
coloracao_letra = "black") {
theme(
plot.title =
element_text(
hjust = 0.5,
color = coloracao_letra,
size = 19),
axis.title.x =
# element_text(
# color = coloracao_letra,
# size = 15,
# angle = 0,),
element_blank(),
axis.title.y = element_text(
color = coloracao_letra,
size = 15,
angle = 90),
axis.text.x = element_text(
color = coloracao_letra,
size = 17),
axis.text.y = element_text(
color = coloracao_letra,
size = 17,
angle = 0),
strip.background = element_rect(fill = bg,
linetype = 1,
size = 0.5,
color = "black"),
strip.text = element_text(size = 17),
panel.background = element_rect(fill = bg),
plot.background = element_rect(fill = bg),
plot.margin = margin(l = 5, r = 10,
b = 5, t = 5)
)
}Time for this code chunk to run: 0.0057380199432373
Time for this code chunk to run: 0.00857710838317871
Time for this code chunk to run: 0.00436186790466309
f <- function(x) {
r <- quantile(x, probs = c(0.05, 0.20, 0.50, 0.80, 0.95))
names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
return(r)
}Time for this code chunk to run: 0.00567889213562012
Time for this code chunk to run: 0.00639009475708008
Time for this code chunk to run: 0.00519108772277832
Time for this code chunk to run: 0.00564098358154297
Time for this code chunk to run: 0.00552582740783691
boxplot_namon <- function(dados = plan_wide_19902020, eixo_x = codigo, eixo_y = nitrogenio_amoniacal, titulo = "Nitrogênio Amoniacal"){
ggplot2::ggplot(
data = dados,
aes(
x = {{eixo_x}},
y = {{eixo_y}}
)
)+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=13.3,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3.7,
ymax=13.3,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=3.7,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
# facet_wrap(~periodo)+
labs(title = titulo,
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE),
max(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = .001,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
}Time for this code chunk to run: 0.00864601135253906
boxplot_turb <- function(dados = plan_wide_19902020, eixo_x = codigo, eixo_y = turbidez, titulo = "Turbidez"){
ggplot2::ggplot(
data = dados,
aes(
x = {{eixo_x}},
y = {{eixo_y}}
)
)+
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=100, ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=40, ymax=100,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=0, ymax=40,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
labs(title = titulo,
x="Estação",
y="UNT")+
scale_y_continuous(expand = expansion(mult = c(0.05, 0.05)),
n.breaks = 8,
limits = c(
# 1,
min(plan_wide_19902020$turbidez, na.rm = TRUE),
# 500
max(plan_wide_19902020$turbidez, na.rm = TRUE)
),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
}Time for this code chunk to run: 0.00695490837097168
Time for this code
chunk to run: 3.12685894966125
Time for this code
chunk to run: 0.739910125732422
Time
for this code chunk to run: 0.755051136016846
Time
for this code chunk to run: 0.657552003860474
ggsave("od.png",
units = c("px"),
width = 4500,
height = 2993,
plot = od,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("od_p1.png",
plot = od_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("od_p2.png",
plot = od_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("od_p3.png",
plot = od_p3,
path = "./graficos",
dpi = 300,
type = "cairo")Time for this code chunk to run: 4.11880302429199
Time
for this code chunk to run: 0.716510057449341
Time
for this code chunk to run: 0.663861036300659
Time
for this code chunk to run: 0.889871120452881
## # A tibble: 9 × 8
## par PM1 PM2 PM3 PM4 PM5 PM6 PM7
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 max 10.8 10.5 10.3 12.1 19.9 10.2 11.1
## 2 p95 9.24 9.8 9.16 9.56 8.92 6.45 8.38
## 3 p80 7.76 8.3 7.52 8.42 6.2 5.5 5.7
## 4 median 6.4 6.9 5.95 6.3 4.2 2.6 2.9
## 5 mean 5.99 6.78 5.98 7.01 4.22 2.98 3.60
## 6 p20 3.84 5.2 4.3 5.72 0.760 0.2 0.8
## 7 p05 2 4.3 3.14 4.94 0.28 0.1 0.128
## 8 min 0.8 2 2.5 4.2 0.1 0.1 0.1
## 9 n 101 101 68 30 97 32 65
## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.4 3.5 4.9 5.01 6.65 10.9
## 2 87398900 1.9 4 5.5 5.33 6.6 12
## 3 87398950 1.7 3.2 5.3 5.06 6.18 8.9
## 4 87398980 1.2 3.8 5.6 5.38 6.6 9.2
## 5 87405500 0.2 1.4 2.55 3.28 4 14.2
## 6 87406900 0 1.1 1.9 2.59 3.15 16
## 7 87409900 0 0.7 2.3 3.12 3.7 10.6
## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.38 3.11 4.41 4.57 6.2 12.4
## 2 87398900 3.52 5.25 5.96 6.61 7.3 13.8
## 3 87398950 1.62 3.68 4.92 5.28 6.64 11.9
## 4 87398980 3.37 5.5 6.17 6.48 7.14 13.1
## 5 87405500 0.2 1.3 2.53 2.83 3.66 9.8
## 6 87406900 0.1 0.865 2.4 2.43 3.05 9.1
## 7 87409900 0.1 0.92 2.03 2.43 3.5 8.1
Time for this code chunk to run: 0.259079217910767
(dbo <- ggplot(plan_wide_19902020,
aes(x = codigo,
y = dbo))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=10,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=5,
ymax=10,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3,
ymax=5,
alpha=1,
fill="#70c18c")+ #classe 2
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=3,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "Demanda Bioquímica de Oxigênio no período 1990-2020",
x="Estação",
y="mg/L",
# caption = "Leonardo Fernandes Wink"
)+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
scale_y_continuous(expand = expansion(mult = c(0.03,0.03)),
n.breaks = 8,
limits = c(1,100),
trans = "log10")+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 60 rows containing non-finite values (`stat_summary()`).
## Removed 60 rows containing non-finite values (`stat_summary()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 22 rows containing missing values.
## Warning: Removed 30 rows containing missing values.
## Warning: Removed 8 rows containing missing values.
Time for
this code chunk to run: 1.66866683959961
Time
for this code chunk to run: 0.771039962768555
Time
for this code chunk to run: 0.874598026275635
Time
for this code chunk to run: 0.757790088653564
Time
for this code chunk to run: 0.771016836166382
Time
for this code chunk to run: 0.681297063827515
Time
for this code chunk to run: 0.64764404296875
(sum_dbo_p1 <- plan_wide_19902020 %>%
select(codigo, dbo, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(dbo,
na.rm = TRUE),
q1 =
quantile(dbo, 0.25,
na.rm = TRUE),
median =
median(dbo,
na.rm = TRUE),
mean =
mean(dbo,
na.rm= TRUE),
q3 =
quantile(dbo, 0.75,
na.rm = TRUE),
max =
max(dbo,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 1 1 2 1.86 2 13
## 2 87398900 1 1 1 1.52 2 6
## 3 87398950 1 1 1 1.66 2 6
## 4 87398980 1 1 1 1.13 1 2
## 5 87405500 1 2 3 5.37 5 64
## 6 87406900 1 4 5 9 11 26
## 7 87409900 2 3 4 6.97 9.5 31
(sum_dbo_p2 <- plan_wide_19902020 %>%
select(codigo, dbo, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(dbo,
na.rm = TRUE),
q1 =
quantile(dbo, 0.25,
na.rm = TRUE),
median =
median(dbo,
na.rm = TRUE),
mean =
mean(dbo,
na.rm= TRUE),
q3 =
quantile(dbo, 0.75,
na.rm = TRUE),
max =
max(dbo,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 1 1 1 1.58 2 5
## 2 87398900 1 1 1 1.40 2 5
## 3 87398950 1 1 1 1.66 2 5
## 4 87398980 1 1 1 1.30 1 5
## 5 87405500 1 2 4 4.67 6.5 14
## 6 87406900 1 3 5 6.53 8 28
## 7 87409900 1 3 6 6.31 9 15
(sum_dbo_p3 <- plan_wide_19902020 %>%
select(codigo, dbo, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(dbo,
na.rm = TRUE),
q1 =
quantile(dbo, 0.25,
na.rm = TRUE),
median =
median(dbo,
na.rm = TRUE),
mean =
mean(dbo,
na.rm= TRUE),
q3 =
quantile(dbo, 0.75,
na.rm = TRUE),
max =
max(dbo,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 1 1 1.5 2.15 3 7
## 2 87398900 1 1 1 1.51 2 5
## 3 87398950 1 1 2 2.65 2 18
## 4 87398980 1 1 1 1.32 2 2
## 5 87405500 1 3 4 5.28 6.25 21
## 6 87406900 1 3 5 6.58 10 24
## 7 87409900 1 3 4.5 6.18 8 18
Time for this code chunk to run: 0.253508806228638
ggsave("dbo.png",
units = c("px"),
width = 4500,
height = 2993,
plot = dbo,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("dbo_p1.png",
plot = dbo_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("dbo_p2.png",
plot = dbo_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("dbo_p3.png",
plot = dbo_p3,
path = "./graficos",
dpi = 300,
type = "cairo")Time for this code chunk to run: 4.29959893226624
(ptot <- ggplot(plan_wide_19902020,
aes(codigo,
fosforo_total))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.15,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.1,
ymax=0.15,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=0.1,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "Fósforo total no período 1990-2020",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.03,0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$fosforo_total, na.rm = TRUE),
max(plan_wide_19902020$fosforo_total), na.rm = TRUE),
trans = "log10",
labels = scales::number_format(accuracy = .001,
decimal.mark = ",",
big.mark = " ")
)+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 134 rows containing non-finite values (`stat_summary()`).
## Removed 134 rows containing non-finite values (`stat_summary()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 47 rows containing missing values.
## Warning: Removed 31 rows containing missing values.
## Warning: Removed 56 rows containing missing values.
Time for this code chunk to
run: 1.57841110229492
(ptot_p1<-ggplot(plan_wide_19902020%>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
fosforo_total))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.15,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.1,
ymax=0.15,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=0.1,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Fósforo total no período 1990-2000",
x="Estação",
y="mg/L")+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_y_continuous(expand = expansion(mult = c(0.03,0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$fosforo_total, na.rm = TRUE),
max(plan_wide_19902020$fosforo_total), na.rm = TRUE),
trans = "log10")+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.740449905395508
(ptot_p2 <- ggplot(plan_wide_19902020%>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
fosforo_total))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.15,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.1,
ymax=0.15,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=0.1,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Fósforo total no período 2000-2010",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.03,0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$fosforo_total, na.rm = TRUE),
max(plan_wide_19902020$fosforo_total), na.rm = TRUE),
trans = "log10")+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.779342889785767
(ptot_p3 <- ggplot(plan_wide_19902020%>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
fosforo_total))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.15,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0.1,
ymax=0.15,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=0.1,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Fósforo total no período 2010-2020",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.03,0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$fosforo_total, na.rm = TRUE),
max(plan_wide_19902020$fosforo_total), na.rm = TRUE),
trans = "log10")+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.707337856292725
(sum_ptot_p1 <- plan_wide_19902020 %>%
select(codigo, fosforo_total, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(fosforo_total, na.rm = TRUE),
q1 =
quantile(fosforo_total, 0.25, na.rm = TRUE),
median =
median(fosforo_total, na.rm = TRUE),
mean =
mean(fosforo_total, na.rm= TRUE),
q3 =
quantile(fosforo_total, 0.75, na.rm = TRUE),
max =
max(fosforo_total, na.rm = TRUE)))## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.0097 0.0593 0.0881 0.123 0.14 0.863
## 2 87398900 0.0023 0.0468 0.0678 0.0747 0.0883 0.247
## 3 87398950 0.0202 0.0544 0.0737 0.0751 0.0904 0.179
## 4 87398980 0.01 0.0254 0.0547 0.0708 0.114 0.189
## 5 87405500 0.017 0.171 0.281 0.417 0.492 2.32
## 6 87406900 0.156 0.270 0.508 0.785 1.07 2.79
## 7 87409900 0.107 0.258 0.384 0.489 0.712 1.53
(sum_ptot_p2 <- plan_wide_19902020 %>%
select(codigo, fosforo_total, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(fosforo_total, na.rm = TRUE),
q1 =
quantile(fosforo_total, 0.25, na.rm = TRUE),
median =
median(fosforo_total, na.rm = TRUE),
mean =
mean(fosforo_total, na.rm= TRUE),
q3 =
quantile(fosforo_total, 0.75, na.rm = TRUE),
max =
max(fosforo_total, na.rm = TRUE)))## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.025 0.094 0.131 0.148 0.16 0.637
## 2 87398900 0.015 0.0764 0.104 0.140 0.164 0.646
## 3 87398950 0.036 0.116 0.171 0.180 0.207 0.485
## 4 87398980 0.0115 0.052 0.076 0.101 0.103 1
## 5 87405500 0.046 0.261 0.406 0.547 0.681 1.98
## 6 87406900 0.056 0.338 0.599 0.752 0.967 3.49
## 7 87409900 0.043 0.325 0.624 0.677 0.989 1.57
(sum_ptot_p3 <- plan_wide_19902020 %>%
select(codigo, fosforo_total, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(fosforo_total, na.rm = TRUE),
q1 =
quantile(fosforo_total, 0.25, na.rm = TRUE),
median =
median(fosforo_total, na.rm = TRUE),
mean =
mean(fosforo_total, na.rm= TRUE),
q3 =
quantile(fosforo_total, 0.75, na.rm = TRUE),
max =
max(fosforo_total, na.rm = TRUE)))## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.061 0.118 0.163 0.166 0.186 0.381
## 2 87398900 0.057 0.0935 0.130 0.163 0.168 0.444
## 3 87398950 0.07 0.132 0.156 0.292 0.221 3.11
## 4 87398980 0.019 0.0625 0.106 0.144 0.170 0.59
## 5 87405500 0.013 0.187 0.332 0.361 0.45 0.803
## 6 87406900 0.089 0.254 0.364 0.448 0.560 1.26
## 7 87409900 0.203 0.259 0.369 0.488 0.564 1.7
Time for this code chunk to run: 0.254715919494629
ggsave("ptot.png",
units = c("px"),
width = 4500,
height = 2993,
plot = ptot,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ptot_p1.png",
plot = ptot_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ptot_p2.png",
plot = ptot_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ptot_p3.png",
plot = ptot_p3,
path = "./graficos",
dpi = 300,
type = "cairo")Time for this code chunk to run: 4.63362312316895
(ecoli <- boxplot_ecoli(
titulo = "*Escherichia coli* no período 1990-2020"
)+
facet_wrap(~periodo)
)Escherichia-coli-gravataí no período 1990-2020
(ecoli <- ggplot(plan_wide_19902020,
aes(codigo,
escherichia_coli))+
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=3200, ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=800, ymax=3200,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=160, ymax=800,
alpha=1,
fill="#70c18c")+ #classe 2
annotate("rect",
xmin=-Inf, xmax=Inf,
ymin=0, ymax=160,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "*Escherichia coli* no período 1990-2020",
x="Estação",
y="NMP/100mL")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
# n.breaks = 9,
n.breaks = 6,
limits = c(min(plan_wide_19902020$escherichia_coli, na.rm = TRUE),
max(plan_wide_19902020$escherichia_coli, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()+
theme(
axis.text.y = element_text(
angle = 90,
# size=15,
# face=2
),
plot.title =
element_markdown(
hjust = 0.5,
color = "black",
size = 19)
)
)Time for this
code chunk to run: 3.55012106895447
(ecoli_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
escherichia_coli))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3200,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=800,
ymax=3200,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=160,
ymax=800,
alpha=1,
fill="#70c18c")+ #classe 2
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=160,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Escherichia coli no período 1990-2000",
x="Estação",
y="NMP/100mL")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$escherichia_coli, na.rm = TRUE),
max(plan_wide_19902020$escherichia_coli, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.889932870864868
(ecoli_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
escherichia_coli))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3200,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=800,
ymax=3200,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=160,
ymax=800,
alpha=1,
fill="#70c18c")+ #classe 2
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=160,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Escherichia coli no período 2000-2010",
x="Estação",
y="NMP/100mL")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$escherichia_coli, na.rm = TRUE),
max(plan_wide_19902020$escherichia_coli, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.830866813659668
(ecoli_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
escherichia_coli))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3200,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=800,
ymax=3200,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=160,
ymax=800,
alpha=1,
fill="#70c18c")+ #classe 2
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=160,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Escherichia coli no período 2010-2020",
x="Estação",
y="NMP/100mL")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$escherichia_coli, na.rm = TRUE),
max(plan_wide_19902020$escherichia_coli, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 1.1879780292511
(sum_ecoli_p1 <- plan_wide_19902020 %>%
select(codigo, escherichia_coli, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(escherichia_coli,
na.rm = TRUE),
q1 =
quantile(escherichia_coli, 0.25,
na.rm = TRUE),
median =
median(escherichia_coli,
na.rm = TRUE),
mean =
mean(escherichia_coli,
na.rm= TRUE),
q3 =
quantile(escherichia_coli, 0.75,
na.rm = TRUE),
max =
max(escherichia_coli,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 32 136 240 854. 720 19200
## 2 87398900 16 68 160 548. 480 7760
## 3 87398950 2.4 12.8 268 4039. 10000 28000
## 4 87398980 4 160 243. 2907. 446 25600
## 5 87405500 1.6 12.8 24 545. 128 18400
## 6 87406900 13.6 61.6 192 718. 414 12800
## 7 87409900 2.4 12.8 64 97.7 128 720
(sum_ecoli_p2 <- plan_wide_19902020 %>%
select(codigo, escherichia_coli, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(escherichia_coli,
na.rm = TRUE),
q1 =
quantile(escherichia_coli, 0.25,
na.rm = TRUE),
median =
median(escherichia_coli,
na.rm = TRUE),
mean =
mean(escherichia_coli,
na.rm= TRUE),
q3 =
quantile(escherichia_coli, 0.75,
na.rm = TRUE),
max =
max(escherichia_coli,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 21.6 91 150 1335. 308 27200
## 2 87398900 11 70 133. 444. 414. 2600
## 3 87398950 20 400 720 935. 1120 5500
## 4 87398980 24 110. 195 410. 289. 8800
## 5 87405500 4.7 162 2400 25445. 12950 490000
## 6 87406900 8 172 12800 66370. 62300 650000
## 7 87409900 16 7355. 35500 72440. 68750 460000
(sum_ecoli_p3 <- plan_wide_19902020 %>%
select(codigo, escherichia_coli, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(escherichia_coli,
na.rm = TRUE),
q1 =
quantile(escherichia_coli, 0.25,
na.rm = TRUE),
median =
median(escherichia_coli,
na.rm = TRUE),
mean =
mean(escherichia_coli,
na.rm= TRUE),
q3 =
quantile(escherichia_coli, 0.75,
na.rm = TRUE),
max =
max(escherichia_coli,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 90 155. 260 409. 451 2420
## 2 87398900 10 52.8 107 245. 313 1553.
## 3 87398950 108. 250 487 1424. 1553. 10462
## 4 87398980 40.8 140. 242. 529. 738. 2400
## 5 87405500 632 8965 19232. 109992. 70750 1400000
## 6 87406900 1440 23100 34500 230828. 140500 3400000
## 7 87409900 2000 20100 38400 83128. 83680 345000
Time for this code chunk to run: 0.24810004234314
ggsave("ecoli.png",
plot = ecoli,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ecoli_p1.png",
plot = ecoli_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ecoli_p2.png",
plot = ecoli_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("ecoli_p3.png",
plot = ecoli_p3,
path = "./graficos",
dpi = 300,
type = "cairo")Time for this code chunk to run: 4.2718288898468
(namon <- plan_wide_19902020 %>%
boxplot_namon(
eixo_y = nitrogenio_amoniacal,
titulo = "Nitrogênio Amoaniacal no período 1990-2020"
)+
facet_wrap(~periodo)
)Time for this code
chunk to run: 1.68492484092712
periodo_inicial <- as.Date("1990-01-01", "%Y-%m-%d")
periodo_final <- as.Date("2021-01-01", "%Y-%m-%d")
(nitro_line <-
plan_wide_19902020 %>%
filter(ano_coleta > "1990" &
ano_coleta <= "2020") %>%
dplyr::select(codigo, nitrogenio_amoniacal, data_coleta, periodo) %>%
# group_by(codigo) %>%
mutate(
ponto_monitoramento = case_when(
codigo == "87398500" ~ "PM1",
codigo == "87398980" ~ "PM2",
codigo == "87398900" ~ "PM3",
codigo == "87398950" ~ "PM4",
codigo == "87405500" ~ "PM5",
codigo == "87406900" ~ "PM6",
codigo == "87409900" ~ "PM7"
)
) %>%
# pivot_wider(
# names_from = codigo,
# values_from = nitro_amon,
# id_cols = data_coleta
# ) %>%
ggplot(
aes(x = data_coleta,
y = nitrogenio_amoniacal,
# color = codigo
))+
# geom_rect(
# aes(xmin = periodo_inicial,
# xmax = periodo_final,
# ymin = 13.3,
# ymax = Inf,
# alpha= 0.005,
# fill= "#ac5079"),
# show.legend = FALSE)+ #>pior classe
# geom_rect(
# aes(xmin = periodo_inicial,
# xmax = periodo_final,
# ymin= 3.7,
# ymax= 13.3,
# alpha= 0.005,
# fill= "#fcf7ab"),
# show.legend = FALSE)+ #classe 3
# geom_rect(
# aes(xmin = periodo_inicial,
# xmax = periodo_final,
# ymin= 0,
# ymax= 3.7,
# alpha= 0.005,
# fill= "blue"
# # "#8dcdeb"
# ),
# show.legend = FALSE)+ #classe 1
annotate("rect",
xmin= periodo_inicial,
xmax= periodo_final,
ymin=13.3,
ymax=Inf,
alpha= 0.7,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin= periodo_inicial,
xmax= periodo_final,
ymin=3.7,
ymax=13.3,
alpha= 0.7,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin= periodo_inicial,
xmax= periodo_final,
ymin= -Inf,
ymax=3.7,
alpha= 0.7,
fill="#8dcdeb")+ #classe 1
geom_line(
# aes(color = codigo),
na.rm = TRUE)+
geom_point(
# aes(color = codigo),
na.rm = TRUE)+
scale_x_date(
limits = as.Date(c(
"1990-01-01",
"2021-01-01"
# NA #pode usar NA também
)),
expand = c(0.0, 0.0),
date_breaks = "10 years",
minor_breaks = "5 years",
date_labels = "%Y",
)+
# geom_smooth(
# # aes(color = codigo),
# method = "lm",
# # formula = y ~ poly(x, 2),
# # span = 0.2,
# se = TRUE, #se deixar TRUE gera o intervalo de confiança de 95%
# aes(group = 1),
# alpha =.5,
# na.rm = TRUE,
# size = 0.3,
# # fullrange = TRUE,
# # show.legend = TRUE
# )+
# stat_smooth(
# geom = "smooth",
# # span = 0.2,
# se = FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
# # aes(group = 1),
# # alpha =.5,
# na.rm = TRUE,
# # size = 0.3,
# fullrange = TRUE,
# show.legend = TRUE
# )+
facet_wrap(
~ponto_monitoramento,
nrow = 4,
)+
theme_bw()
)Time
for this code chunk to run: 1.26403880119324
(namon_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
nitrogenio_amoniacal))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=13.3,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3.7,
ymax=13.3,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=3.7,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Nitrogênio amoniacal no período 1990-2000",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE),
max(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = .001,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.758342981338501
(namon_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
nitrogenio_amoniacal))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=13.3,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3.7,
ymax=13.3,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=3.7,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Nitrogênio amoniacal no período 2000-2010",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE),
max(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = .001,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.794203996658325
(namon_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
nitrogenio_amoniacal))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=13.3,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=3.7,
ymax=13.3,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=3.7,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Nitrogênio amoniacal no período 2010-2020",
x="Estação",
y="mg/L")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 9,
limits = c(min(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE),
max(plan_wide_19902020$nitrogenio_amoniacal, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = .001,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.768031120300293
grid.arrange(namon_p1, namon_p2, namon_p3, ncol = 3)Time
for this code chunk to run: 2.33321499824524
(sum_namon_p1 <- plan_wide_19902020 %>%
select(codigo, nitrogenio_amoniacal, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(nitrogenio_amoniacal,
na.rm = TRUE),
q1 =
quantile(nitrogenio_amoniacal, 0.25,
na.rm = TRUE),
median =
median(nitrogenio_amoniacal,
na.rm = TRUE),
mean =
mean(nitrogenio_amoniacal,
na.rm= TRUE),
q3 =
quantile(nitrogenio_amoniacal, 0.75,
na.rm = TRUE),
max =
max(nitrogenio_amoniacal,
na.rm = TRUE),
n =
length(nitrogenio_amoniacal)
)
)## # A tibble: 7 × 8
## codigo min q1 median mean q3 max n
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
## 1 87398500 0.08 0.165 0.205 0.246 0.28 0.91 101
## 2 87398900 0.087 0.17 0.2 0.248 0.242 1.13 101
## 3 87398950 Inf NA NA NaN NA -Inf 68
## 4 87398980 0.027 0.12 0.15 0.158 0.188 0.3 30
## 5 87405500 0.43 0.875 1.74 4.28 5.88 17.7 97
## 6 87406900 0.51 1.14 2.78 5.35 7.50 26 32
## 7 87409900 Inf NA NA NaN NA -Inf 65
(sum_namon_p2 <- plan_wide_19902020 %>%
select(codigo, nitrogenio_amoniacal, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(nitrogenio_amoniacal,
na.rm = TRUE),
q1 =
quantile(nitrogenio_amoniacal, 0.25,
na.rm = TRUE),
median =
median(nitrogenio_amoniacal,
na.rm = TRUE),
mean =
mean(nitrogenio_amoniacal,
na.rm= TRUE),
q3 =
quantile(nitrogenio_amoniacal, 0.75,
na.rm = TRUE),
max =
max(nitrogenio_amoniacal,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.031 0.16 0.21 0.259 0.29 1.22
## 2 87398900 0.03 0.16 0.21 0.284 0.342 2.77
## 3 87398950 0.044 0.214 0.276 0.268 0.349 0.413
## 4 87398980 0.024 0.098 0.14 0.161 0.21 0.551
## 5 87405500 0.038 0.79 2.09 3.49 4.54 18
## 6 87406900 0.03 1.05 2.66 4.27 5.62 19.4
## 7 87409900 0.453 0.78 2.46 3.84 4.77 16.6
(sum_namon_p3 <- plan_wide_19902020 %>%
select(codigo, nitrogenio_amoniacal, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(nitrogenio_amoniacal,
na.rm = TRUE),
q1 =
quantile(nitrogenio_amoniacal, 0.25,
na.rm = TRUE),
median =
median(nitrogenio_amoniacal,
na.rm = TRUE),
mean =
mean(nitrogenio_amoniacal,
na.rm= TRUE),
q3 =
quantile(nitrogenio_amoniacal, 0.75,
na.rm = TRUE),
max =
max(nitrogenio_amoniacal,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 0.03 0.085 0.1 0.150 0.198 0.419
## 2 87398900 0.03 0.1 0.192 0.213 0.248 0.699
## 3 87398950 0.02 0.165 0.263 0.315 0.4 0.951
## 4 87398980 0.02 0.06 0.1 0.179 0.235 0.717
## 5 87405500 0.05 0.808 1.60 2.55 3.78 9.12
## 6 87406900 0.03 1.09 2.16 3.61 5.02 21.2
## 7 87409900 0.04 1.44 2.5 3.40 4.39 18.8
Time for this code chunk to run: 0.327318906784058
ggsave("namon.png",
units = c("px"),
width = 4500,
height = 2993,
plot = namon,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("namon_p1.png",
plot = namon_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("namon_p2.png",
plot = namon_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("namon_p3.png",
plot = namon_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("namon_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(namon_p1, namon_p2, namon_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time
for this code chunk to run: 7.71082401275635
(turb <- ggplot(plan_wide_19902020,
aes(codigo,
turbidez))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=100,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=40,
ymax=100,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=40,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "Turbidez no período 1990-2020",
x="Estação",
y="UNT")+
scale_y_continuous(expand = expansion(mult = c(0.05, 0.05)),
n.breaks = 8,
limits = c(
# 1,
min(plan_wide_19902020$turbidez, na.rm = TRUE),
# 500
max(plan_wide_19902020$turbidez, na.rm = TRUE)
),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time for this code chunk
to run: 1.50802898406982
(turb_line <- plan_wide_19902020 %>%
filter(ano_coleta > "1990" &
ano_coleta <= "2020") %>%
select(codigo, turbidez, data_coleta, periodo) %>%
group_by(codigo) %>%
ggplot(
aes(x = data_coleta,
y = turbidez,
color = codigo
))+
geom_line(
# aes(color = codigo),
na.rm = TRUE)+
geom_point(
# aes(color = codigo),
na.rm = TRUE)+
scale_x_date(
limits = as.Date(c(
"1990-01-01",
"2021-01-01"
# NA #pode usar NA também
)),
expand = c(0.0, 0.0),
date_breaks = "10 years",
minor_breaks = "5 years",
date_labels = "%Y",
)+
# geom_smooth(
# # aes(color = codigo),
# method = "lm",
# # formula = y ~ poly(x, 2),
# # span = 0.2,
# se = TRUE, #se deixar TRUE gera o intervalo de confiança de 95%
# aes(group = 1),
# alpha =.5,
# na.rm = TRUE,
# size = 0.3,
# # fullrange = TRUE,
# # show.legend = TRUE
# )+
# stat_smooth(
# geom = "smooth",
# # span = 0.2,
# se = FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
# # aes(group = 1),
# # alpha =.5,
# na.rm = TRUE,
# # size = 0.3,
# fullrange = TRUE,
# show.legend = TRUE
# )+
facet_wrap(
~codigo,
nrow = 4,
)+
theme_bw()
)Time
for this code chunk to run: 1.31414103507996
(turb_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
turbidez))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=100,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=40,
ymax=100,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=40,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Turbidez no período 1990-2000",
x="Estação",
y="UNT")+
scale_y_continuous(expand = expansion(mult = c(0.05, 0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$turbidez, na.rm = TRUE),
max(plan_wide_19902020$turbidez, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.923189163208008
(turb_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
turbidez))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=100,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=40,
ymax=100,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=40,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Turbidez no período 2000-2010",
x="Estação",
y="UNT")+
scale_y_continuous(expand = expansion(mult = c(0.05, 0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$turbidez, na.rm = TRUE),
max(plan_wide_19902020$turbidez, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.764994859695435
(turb_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
turbidez))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=100,
ymax=Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=40,
ymax=100,
alpha=1,
fill="#fcf7ab")+ #classe 3
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=0,
ymax=40,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Turbidez no período 2010-2020",
x="Estação",
y="UNT")+
scale_y_continuous(expand = expansion(mult = c(0.05, 0.03)),
n.breaks = 8,
limits = c(min(plan_wide_19902020$turbidez, na.rm = TRUE),
max(plan_wide_19902020$turbidez, na.rm = TRUE)),
trans = "log10",
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.734085083007812
grid.arrange(turb_p1, turb_p2, turb_p3, ncol = 3)Time
for this code chunk to run: 2.32150292396545
(sum_turb_p1 <- plan_wide_19902020 %>%
select(codigo, turbidez, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(turbidez,
na.rm = TRUE),
q1 =
quantile(turbidez, 0.25,
na.rm = TRUE),
median =
median(turbidez,
na.rm = TRUE),
mean =
mean(turbidez,
na.rm= TRUE),
q3 =
quantile(turbidez, 0.75,
na.rm = TRUE),
max =
max(turbidez,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 6.2 19 34.5 63.5 67 461
## 2 87398900 9 19 49.5 61.5 73.8 460
## 3 87398950 9.6 16 22 33.3 48.8 144
## 4 87398980 16 32.8 43 66.8 90.5 190
## 5 87405500 8.5 23.5 47 47.5 58 159
## 6 87406900 33 54.8 67 77.7 81.5 199
## 7 87409900 5.8 15 25 32.2 48 76
(sum_turb_p2 <- plan_wide_19902020 %>%
select(codigo, turbidez, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(turbidez,
na.rm = TRUE),
q1 =
quantile(turbidez, 0.25,
na.rm = TRUE),
median =
median(turbidez,
na.rm = TRUE),
mean =
mean(turbidez,
na.rm= TRUE),
q3 =
quantile(turbidez, 0.75,
na.rm = TRUE),
max =
max(turbidez,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 9 41.2 55.5 71.1 74.2 428
## 2 87398900 39 57 78 107. 116. 475
## 3 87398950 39 47 64 96.5 90 330
## 4 87398980 24 37 50 64.5 87 176
## 5 87405500 32 46 63.5 70.3 76 341
## 6 87406900 35 49 62 69.9 75.5 284
## 7 87409900 40 45 60 70.4 90 151
(sum_turb_p3 <- plan_wide_19902020 %>%
select(codigo, turbidez, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(turbidez,
na.rm = TRUE),
q1 =
quantile(turbidez, 0.25,
na.rm = TRUE),
median =
median(turbidez,
na.rm = TRUE),
mean =
mean(turbidez,
na.rm= TRUE),
q3 =
quantile(turbidez, 0.75,
na.rm = TRUE),
max =
max(turbidez,
na.rm = TRUE))
) ## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 8.52 16.4 29 33.3 43 85
## 2 87398900 14.8 39.2 48.3 66.7 73.4 299
## 3 87398950 16 29.9 41 51.6 65 230
## 4 87398980 11 19.4 33.6 39.5 42.2 110.
## 5 87405500 10.0 29.0 41 42.9 54.5 131
## 6 87406900 9.62 23 39 41.2 52 122
## 7 87409900 9.68 22.0 34.0 40.5 47 182.
Time for this code chunk to run: 0.360772132873535
ggsave("turb.png",
units = c("px"),
width = 4500,
height = 2993,
plot = turb,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("turb_p1.png",
plot = turb_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("turb_p2.png",
plot = turb_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("turb_p3.png",
plot = turb_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("turb_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(turb_p1, turb_p2, turb_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time
for this code chunk to run: 8.09145998954773
(pH <- ggplot(plan_wide_19902020,
aes(codigo,
pH))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=6,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=9,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=6,
ymax=9,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "pH no período 1990-2020",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 8,
limits = c(4,11),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time for this code chunk to
run: 2.29897689819336
(pH_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
pH))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=6,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=9,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=6,
ymax=9,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "pH no período 1990-2000",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 8,
limits = c(4,11),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.825370073318481
(pH_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
pH))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=6,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=9,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=6,
ymax=9,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "pH no período 2000-2010",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 8,
limits = c(4,11),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.700754880905151
(pH_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
pH))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=6,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=9,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=6,
ymax=9,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "pH no período 2010-2020",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.01)),
n.breaks = 8,
limits = c(4,11),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.680684089660645
grid.arrange(pH_p1, pH_p2, pH_p3, ncol = 3)Time
for this code chunk to run: 2.04337596893311
(sum_pH_p1 <- plan_wide_19902020 %>%
select(codigo, pH, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(pH,
na.rm = TRUE),
q1 =
quantile(pH, 0.25,
na.rm = TRUE),
median =
median(pH,
na.rm = TRUE),
mean =
mean(pH,
na.rm= TRUE),
q3 =
quantile(pH, 0.75,
na.rm = TRUE),
max =
max(pH,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 5 6.18 6.59 6.51 6.82 7.9
## 2 87398900 5.2 6 6.3 6.33 6.63 7.9
## 3 87398950 5.4 6.29 6.4 6.49 6.72 8.1
## 4 87398980 5.3 5.93 6.2 6.16 6.3 7.3
## 5 87405500 5 6.3 6.4 6.47 6.7 9.3
## 6 87406900 5.5 6.18 6.45 6.43 6.8 7.3
## 7 87409900 4.5 6.2 6.4 6.44 6.7 7.4
(sum_pH_p2 <- plan_wide_19902020 %>%
select(codigo, pH, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(pH,
na.rm = TRUE),
q1 =
quantile(pH, 0.25,
na.rm = TRUE),
median =
median(pH,
na.rm = TRUE),
mean =
mean(pH,
na.rm= TRUE),
q3 =
quantile(pH, 0.75,
na.rm = TRUE),
max =
max(pH,
na.rm = TRUE))
) ## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 5.3 6.3 6.6 6.59 6.88 7.9
## 2 87398900 5.5 6.4 6.65 6.63 6.9 7.5
## 3 87398950 6 6.6 6.8 6.89 7.25 7.6
## 4 87398980 5.8 6.3 6.5 6.63 7 7.5
## 5 87405500 5.2 6.4 6.6 6.68 6.9 8.3
## 6 87406900 5.5 6.4 6.7 6.66 6.9 8.6
## 7 87409900 5.8 6.5 6.8 6.77 7 8.4
(sum_pH_p3 <- plan_wide_19902020 %>%
select(codigo, pH, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(pH,
na.rm = TRUE),
q1 =
quantile(pH, 0.25,
na.rm = TRUE),
median =
median(pH,
na.rm = TRUE),
mean =
mean(pH,
na.rm= TRUE),
q3 =
quantile(pH, 0.75,
na.rm = TRUE),
max =
max(pH,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 5.47 6.28 6.42 6.47 6.60 7.3
## 2 87398900 5.68 6.36 6.5 6.57 6.84 7.4
## 3 87398950 5.71 6.28 6.46 6.46 6.68 7
## 4 87398980 5.42 6.10 6.36 6.39 6.6 7.2
## 5 87405500 5.64 6.34 6.5 6.49 6.7 7.01
## 6 87406900 5.6 6.4 6.48 6.51 6.77 7.3
## 7 87409900 5.59 6.46 6.6 6.57 6.76 7.2
Time for this code chunk to run: 0.251217126846313
ggsave("pH.png",
units = c("px"),
width = 4500,
height = 2993,
plot = pH,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("pH_p1.png",
plot = pH_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("pH_p2.png",
plot = pH_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("pH_p3.png",
plot = pH_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("pH_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(pH_p1, pH_p2, pH_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time for
this code chunk to run: 7.51497602462769
(SolTot <- ggplot(plan_wide_19902020,
aes(codigo,
solidos_totais))+
annotate("rect",
xmin = -Inf, xmax = Inf,
ymin = 500, ymax = Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "Sólidos totais no período 1990-2020",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$solidos_totais, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time for this code
chunk to run: 1.84275102615356
(SolTot_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000"),
aes(codigo,
solidos_totais))+
annotate("rect",
xmin = -Inf, xmax = Inf,
ymin = 500, ymax = Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Sólidos totais no período 1990-2000",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$solidos_totais, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.935385227203369
(SolTot_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
solidos_totais))+
annotate("rect",
xmin = -Inf, xmax = Inf,
ymin = 500, ymax = Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Sólidos totais no período 2000-2010",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$solidos_totais, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.963917016983032
(SolTot_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
solidos_totais))+
annotate("rect",
xmin = -Inf, xmax = Inf,
ymin = 500, ymax = Inf,
alpha=1,
fill="#ac5079")+ #>pior classe
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Sólidos totais no período 2010-2020",
x="Estação",
y="")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$solidos_totais, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.909337997436523
grid.arrange(SolTot_p1, SolTot_p2, SolTot_p3, ncol = 3)Time
for this code chunk to run: 2.60734796524048
(sum_SolTot_p1 <- plan_wide_19902020 %>%
select(codigo, solidos_totais, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(solidos_totais,
na.rm = TRUE),
q1 =
quantile(solidos_totais, 0.25,
na.rm = TRUE),
median =
median(solidos_totais,
na.rm = TRUE),
mean =
mean(solidos_totais,
na.rm= TRUE),
q3 =
quantile(solidos_totais, 0.75,
na.rm = TRUE),
max =
max(solidos_totais,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 46 84.5 95 122. 120 510
## 2 87398900 18 74.5 97 111. 122. 474
## 3 87398950 10 76.5 91 90.9 106. 155
## 4 87398980 48 63.5 81.5 104. 126. 337
## 5 87405500 70 101 121 133. 151 361
## 6 87406900 89 118 155 165. 210 279
## 7 87409900 20 99.5 122 128. 143 381
(sum_SolTot_p2 <- plan_wide_19902020 %>%
select(codigo, solidos_totais, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(solidos_totais,
na.rm = TRUE),
q1 =
quantile(solidos_totais, 0.25,
na.rm = TRUE),
median =
median(solidos_totais,
na.rm = TRUE),
mean =
mean(solidos_totais,
na.rm= TRUE),
q3 =
quantile(solidos_totais, 0.75,
na.rm = TRUE),
max =
max(solidos_totais,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 28 80 100 111. 123. 412
## 2 87398900 42 82 102. 128. 140. 489
## 3 87398950 46 94.2 108. 126. 127. 318
## 4 87398980 40 61 77 85.3 96 228
## 5 87405500 48 102 133 148. 170. 522
## 6 87406900 50 109 134. 154. 170. 670
## 7 87409900 56 112. 156 167. 190. 599
(sum_SolTot_p3 <- plan_wide_19902020 %>%
select(codigo, solidos_totais, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(solidos_totais,
na.rm = TRUE),
q1 =
quantile(solidos_totais, 0.25,
na.rm = TRUE),
median =
median(solidos_totais,
na.rm = TRUE),
mean =
mean(solidos_totais,
na.rm= TRUE),
q3 =
quantile(solidos_totais, 0.75,
na.rm = TRUE),
max =
max(solidos_totais,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 61 69 90 82.8 96 101
## 2 87398900 41 77 104 120. 127 308
## 3 87398950 45 93 101 109. 117 221
## 4 87398980 55 62.8 80 79.9 95 109
## 5 87405500 83 89.2 108. 124. 162. 195
## 6 87406900 50 106 117 135. 163 246
## 7 87409900 75 103 115 131. 145 251
Time for this code chunk to run: 0.324244976043701
ggsave("SolTot.png",
units = c("px"),
width = 4500,
height = 2993,
plot = SolTot,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("SolTot_p1.png",
plot = SolTot_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("SolTot_p2.png",
plot = SolTot_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("SolTot_p3.png",
plot = SolTot_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("SolTot_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(SolTot_p1, SolTot_p2, SolTot_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time
for this code chunk to run: 6.9107129573822
Time for this code chunk to
run: 1.27456784248352
Time
for this code chunk to run: 0.590227127075195
Time
for this code chunk to run: 0.628800868988037
Time
for this code chunk to run: 0.537429094314575
grid.arrange(iqa_p1, iqa_p2, iqa_p3, ncol = 3)Time
for this code chunk to run: 1.61882710456848
(sum_IQA_p1 <- plan_wide_19902020 %>%
select(codigo, iqa, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(iqa,
na.rm = TRUE),
q1 =
quantile(iqa, 0.25,
na.rm = TRUE),
median =
median(iqa,
na.rm = TRUE),
mean =
mean(iqa,
na.rm= TRUE),
q3 =
quantile(iqa, 0.75,
na.rm = TRUE),
max =
max(iqa,
na.rm = TRUE),
n =
length(iqa)
)
)## # A tibble: 7 × 8
## codigo min q1 median mean q3 max n
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
## 1 87398500 27.0 35.7 40.9 40.7 46.2 52.2 101
## 2 87398900 27.8 37.9 42.9 43.0 48.0 58.5 101
## 3 87398950 32.8 36.8 41.4 43.2 48.6 61.9 68
## 4 87398980 29.2 35.8 40.4 40.3 44.8 51.9 30
## 5 87405500 24.8 34.9 41.2 40.3 46.9 57.6 97
## 6 87406900 24.7 31.3 37.8 37.4 44.4 49.0 32
## 7 87409900 23.6 31.9 37.1 38.8 46.2 55.4 65
(sum_IQA_p2 <- plan_wide_19902020 %>%
select(codigo, iqa, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(iqa,
na.rm = TRUE),
q1 =
quantile(iqa, 0.25,
na.rm = TRUE),
median =
median(iqa,
na.rm = TRUE),
mean =
mean(iqa,
na.rm= TRUE),
q3 =
quantile(iqa, 0.75,
na.rm = TRUE),
max =
max(iqa,
na.rm = TRUE),
n =
length(iqa)
)
)## # A tibble: 7 × 8
## codigo min q1 median mean q3 max n
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
## 1 87398500 27.8 34.6 40.0 39.5 43.5 48.7 75
## 2 87398900 28.5 35.1 37.6 38.3 40.6 48.5 77
## 3 87398950 21.1 29.4 32.7 32.8 36.8 44.0 30
## 4 87398980 24.5 35.7 39.4 39.5 43.4 52.1 66
## 5 87405500 19.8 28.7 31.5 31.9 35.7 48.8 78
## 6 87406900 17.1 25.3 29.0 29.5 32.8 44.1 79
## 7 87409900 16.2 20.5 26.1 25.0 29.8 33.1 31
(sum_IQA_p3 <- plan_wide_19902020 %>%
select(codigo, iqa, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
# ?as_factor(codigo) %>%
group_by(codigo) %>%
summarize(
min =
min(iqa,
na.rm = TRUE),
q1 =
quantile(iqa, 0.25,
na.rm = TRUE),
median =
median(iqa,
na.rm = TRUE),
mean =
mean(iqa,
na.rm= TRUE),
q3 =
quantile(iqa, 0.75,
na.rm = TRUE),
max =
max(iqa,
na.rm = TRUE),
n =
length(iqa),
NAs =
sum(is.na(iqa))
) %>%
mutate(
"%NA" = NAs/n*100
)
)## # A tibble: 7 × 10
## codigo min q1 median mean q3 max n NAs `%NA`
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <dbl>
## 1 87398500 40.2 42.5 45.4 44.2 45.5 47.2 34 29 85.3
## 2 87398900 34.1 38.6 41.2 40.2 42.9 44.4 36 32 88.9
## 3 87398950 36.7 39.5 42.4 41.5 44.4 44.6 35 31 88.6
## 4 87398980 40.0 40.0 40.0 40.0 40.0 40.0 28 27 96.4
## 5 87405500 30.8 31.6 32.5 32.5 33.3 34.1 33 31 93.9
## 6 87406900 22.9 24.4 25.9 25.3 26.5 27.2 35 32 91.4
## 7 87409900 24.1 25.1 27.3 26.9 28.2 29.7 37 32 86.5
Time for this code chunk to run: 0.249190807342529
ggsave("iqa.png",
units = c("px"),
width = 4500,
height = 2993,
plot = iqa,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("iqa_p1.png",
plot = iqa_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("iqa_p2.png",
plot = iqa_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("iqa_p3.png",
plot = iqa_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("iqa_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(iqa_p1, iqa_p2, iqa_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time
for this code chunk to run: 6.1524019241333
parametros_IQA %>%
dplyr::select(
-codigo,
-ano_coleta,
-nitrogenio_total
) %>%
# group_by(codigo) %>%
rename(
CE = condutividade,
E_coli = escherichia_coli,
OD = oxigenio_dissolvido,
ST = solidos_totais,
Turb = turbidez,
Temp = temperatura_agua,
Ptot = fosforo_total,
# NTot = nitrogenio_total,
NAmon = nitrogenio_amoniacal,
NTK = nitrogenio_kjeldahl
) %>%
ggcorr(
method = "complete.obs",
# "pearson",
# "pairwise",
name = "Correlação",
label = TRUE,
label_alpha = TRUE,
digits = 3,
low = "#3B9AB2",
mid = "#EEEEEE",
high = "#F21A00",
# palette = "RdYlBu",
layout.exp = 0,
legend.position = "left",
label_round = 3,
# legend.size = 18,
geom = "tile",
nbreaks = 10,
)+
labs(title = "Correlação entre parâmetros físico-químicos na\nBacia Hidrográfica do rio Gravataí no período 1990-2020")+
theme_linedraw()+
theme(
legend.position = c(0.15, 0.6),
legend.title = element_text(size = 16),
legend.text = element_text(size = 14),
# legend.spacing = unit(element_text(),
# units = 5)
plot.title = element_text(hjust = 0.5,
size = 16)
)correlação-parametros-qualidade-agua-gravataí no período 1990-2020
# Gráfico das correlações entre todos os parâmetros com significância
correl_IQA <- parametros_IQA %>%
dplyr::select(-codigo) %>%
ggpairs(title = "Correlação entre parâmetros que compõem o IQA",
axisLabels = "show")
correlacao_pIQA <- parametros_IQA %>%
group_by(codigo) %>%
correlation::correlation()
correlacao_pIQA %>%
# glimpse()
filter(
p < 0.001
) %>%
t() %>%
summary()## 87398500 - oxigenio_dissolvido 87398500 - dbo 87398500 - fosforo_total
## Min. :-0.4765 Min. :0.4176 Min. :0.3641
## 1st Qu.: 1.0000 1st Qu.:1.0000 1st Qu.:1.0000
## Median : 1.0000 Median :1.0000 Median :1.0000
## Mean : 0.7836 Mean :0.9552 Mean :0.8668
## 3rd Qu.: 1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. : 1.0000 Max. :1.0000 Max. :1.0000
## 87398500 - nitrogenio_kjeldahl 87398500 - nitrogenio_total 87398500 - turbidez
## Min. :0.4105 Min. :0.4915 Min. :0.3641
## 1st Qu.:0.7854 1st Qu.:1.0000 1st Qu.:1.0000
## Median :1.0000 Median :1.0000 Median :1.0000
## Mean :0.8634 Mean :0.9609 Mean :0.9133
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000
## 87398500 - nitrogenio_amoniacal 87398500 - pH 87398500 - temperatura_agua
## Min. :1 Min. :1 Min. :-0.4765
## 1st Qu.:1 1st Qu.:1 1st Qu.: 1.0000
## Median :1 Median :1 Median : 1.0000
## Mean :1 Mean :1 Mean : 0.8864
## 3rd Qu.:1 3rd Qu.:1 3rd Qu.: 1.0000
## Max. :1 Max. :1 Max. : 1.0000
## 87398500 - solidos_totais 87398500 - escherichia_coli 87398500 - ano_coleta
## Min. :0.4915 Min. :1 Min. :-0.3361
## 1st Qu.:0.8978 1st Qu.:1 1st Qu.: 1.0000
## Median :1.0000 Median :1 Median : 1.0000
## Mean :0.8976 Mean :1 Mean : 0.8972
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.: 1.0000
## Max. :1.0000 Max. :1 Max. : 1.0000
## 87398500 - condutividade 87398900 - oxigenio_dissolvido 87398900 - dbo
## Min. :1 Min. :-0.3893 Min. :0.3880
## 1st Qu.:1 1st Qu.: 1.0000 1st Qu.:1.0000
## Median :1 Median : 1.0000 Median :1.0000
## Mean :1 Mean : 0.8931 Mean :0.9529
## 3rd Qu.:1 3rd Qu.: 1.0000 3rd Qu.:1.0000
## Max. :1 Max. : 1.0000 Max. :1.0000
## 87398900 - fosforo_total 87398900 - nitrogenio_kjeldahl
## Min. :0.3526 Min. :0.4385
## 1st Qu.:0.5279 1st Qu.:0.9982
## Median :1.0000 Median :1.0000
## Mean :0.8295 Mean :0.9000
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87398900 - nitrogenio_total 87398900 - turbidez
## Min. :0.4067 Min. :0.4067
## 1st Qu.:0.9982 1st Qu.:0.9070
## Median :1.0000 Median :1.0000
## Mean :0.8647 Mean :0.8634
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87398900 - nitrogenio_amoniacal 87398900 - pH 87398900 - temperatura_agua
## Min. :0.3880 Min. :1 Min. :-0.3893
## 1st Qu.:0.7489 1st Qu.:1 1st Qu.: 1.0000
## Median :1.0000 Median :1 Median : 1.0000
## Mean :0.8447 Mean :1 Mean : 0.8931
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.: 1.0000
## Max. :1.0000 Max. :1 Max. : 1.0000
## 87398900 - solidos_totais 87398900 - escherichia_coli 87398900 - ano_coleta
## Min. :0.4234 Min. :1 Min. :0.3526
## 1st Qu.:0.9070 1st Qu.:1 1st Qu.:1.0000
## Median :1.0000 Median :1 Median :1.0000
## Mean :0.8748 Mean :1 Mean :0.9502
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.:1.0000
## Max. :1.0000 Max. :1 Max. :1.0000
## 87398900 - condutividade 87398950 - oxigenio_dissolvido 87398950 - dbo
## Min. :1 Min. :-0.5945 Min. :1
## 1st Qu.:1 1st Qu.: 1.0000 1st Qu.:1
## Median :1 Median : 1.0000 Median :1
## Mean :1 Mean : 0.6475 Mean :1
## 3rd Qu.:1 3rd Qu.: 1.0000 3rd Qu.:1
## Max. :1 Max. : 1.0000 Max. :1
## 87398950 - fosforo_total 87398950 - nitrogenio_kjeldahl
## Min. :0.5497 Min. :-0.5359
## 1st Qu.:1.0000 1st Qu.: 1.0000
## Median :1.0000 Median : 1.0000
## Mean :0.9307 Mean : 0.8593
## 3rd Qu.:1.0000 3rd Qu.: 1.0000
## Max. :1.0000 Max. : 1.0000
## 87398950 - nitrogenio_total 87398950 - turbidez
## Min. :0.5497 Min. :0.8455
## 1st Qu.:1.0000 1st Qu.:1.0000
## Median :1.0000 Median :1.0000
## Mean :0.9647 Mean :0.9881
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87398950 - nitrogenio_amoniacal 87398950 - pH 87398950 - temperatura_agua
## Min. :1 Min. :1 Min. :-0.5945
## 1st Qu.:1 1st Qu.:1 1st Qu.: 1.0000
## Median :1 Median :1 Median : 1.0000
## Mean :1 Mean :1 Mean : 0.8773
## 3rd Qu.:1 3rd Qu.:1 3rd Qu.: 1.0000
## Max. :1 Max. :1 Max. : 1.0000
## 87398950 - solidos_totais 87398950 - escherichia_coli 87398950 - ano_coleta
## Min. :0.8455 Min. :1 Min. :1
## 1st Qu.:1.0000 1st Qu.:1 1st Qu.:1
## Median :1.0000 Median :1 Median :1
## Mean :0.9881 Mean :1 Mean :1
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.:1
## Max. :1.0000 Max. :1 Max. :1
## 87398950 - condutividade 87398980 - oxigenio_dissolvido 87398980 - dbo
## Min. :-0.4515 Min. :1 Min. :1
## 1st Qu.: 1.0000 1st Qu.:1 1st Qu.:1
## Median : 1.0000 Median :1 Median :1
## Mean : 0.8318 Mean :1 Mean :1
## 3rd Qu.: 1.0000 3rd Qu.:1 3rd Qu.:1
## Max. : 1.0000 Max. :1 Max. :1
## 87398980 - fosforo_total 87398980 - nitrogenio_kjeldahl
## Min. :1 Min. :1
## 1st Qu.:1 1st Qu.:1
## Median :1 Median :1
## Mean :1 Mean :1
## 3rd Qu.:1 3rd Qu.:1
## Max. :1 Max. :1
## 87398980 - nitrogenio_total 87398980 - turbidez
## Min. :1 Min. :0.5681
## 1st Qu.:1 1st Qu.:1.0000
## Median :1 Median :1.0000
## Mean :1 Mean :0.9402
## 3rd Qu.:1 3rd Qu.:1.0000
## Max. :1 Max. :1.0000
## 87398980 - nitrogenio_amoniacal 87398980 - pH 87398980 - temperatura_agua
## Min. :1 Min. :1 Min. :0.5681
## 1st Qu.:1 1st Qu.:1 1st Qu.:1.0000
## Median :1 Median :1 Median :1.0000
## Mean :1 Mean :1 Mean :0.9668
## 3rd Qu.:1 3rd Qu.:1 3rd Qu.:1.0000
## Max. :1 Max. :1 Max. :1.0000
## 87398980 - solidos_totais 87398980 - escherichia_coli 87398980 - ano_coleta
## Min. :0.6547 Min. :1 Min. :1
## 1st Qu.:1.0000 1st Qu.:1 1st Qu.:1
## Median :1.0000 Median :1 Median :1
## Mean :0.9734 Mean :1 Mean :1
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.:1
## Max. :1.0000 Max. :1 Max. :1
## 87398980 - condutividade 87405500 - oxigenio_dissolvido 87405500 - dbo
## Min. :1 Min. :-0.3314 Min. :0.4199
## 1st Qu.:1 1st Qu.: 1.0000 1st Qu.:0.5402
## Median :1 Median : 1.0000 Median :1.0000
## Mean :1 Mean : 0.8976 Mean :0.7900
## 3rd Qu.:1 3rd Qu.: 1.0000 3rd Qu.:1.0000
## Max. :1 Max. : 1.0000 Max. :1.0000
## 87405500 - fosforo_total 87405500 - nitrogenio_kjeldahl
## Min. :-0.3314 Min. :0.3930
## 1st Qu.: 0.4828 1st Qu.:0.6656
## Median : 0.7834 Median :0.9319
## Mean : 0.6601 Mean :0.8206
## 3rd Qu.: 1.0000 3rd Qu.:1.0000
## Max. : 1.0000 Max. :1.0000
## 87405500 - nitrogenio_total 87405500 - turbidez
## Min. :0.5052 Min. :0.3797
## 1st Qu.:0.6036 1st Qu.:1.0000
## Median :0.9033 Median :1.0000
## Mean :0.8197 Mean :0.9523
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87405500 - nitrogenio_amoniacal 87405500 - pH 87405500 - temperatura_agua
## Min. :0.4993 Min. :0.3109 Min. :0.3109
## 1st Qu.:0.7350 1st Qu.:0.4284 1st Qu.:0.4534
## Median :0.9033 Median :0.5052 Median :0.5711
## Mean :0.8353 Mean :0.6886 Mean :0.7138
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000
## 87405500 - solidos_totais 87405500 - escherichia_coli 87405500 - ano_coleta
## Min. :0.3797 Min. :1 Min. :1
## 1st Qu.:0.4477 1st Qu.:1 1st Qu.:1
## Median :0.6036 Median :1 Median :1
## Mean :0.6652 Mean :1 Mean :1
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.:1
## Max. :1.0000 Max. :1 Max. :1
## 87405500 - condutividade 87406900 - oxigenio_dissolvido 87406900 - dbo
## Min. :0.4527 Min. :-0.5366 Min. :0.5144
## 1st Qu.:0.5737 1st Qu.: 1.0000 1st Qu.:0.7408
## Median :0.8099 Median : 1.0000 Median :1.0000
## Mean :0.7836 Mean : 0.6685 Mean :0.8530
## 3rd Qu.:1.0000 3rd Qu.: 1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. : 1.0000 Max. :1.0000
## 87406900 - fosforo_total 87406900 - nitrogenio_kjeldahl
## Min. :-0.3894 Min. :-0.5366
## 1st Qu.: 0.6154 1st Qu.: 0.6958
## Median : 0.7260 Median : 0.9305
## Mean : 0.6906 Mean : 0.7673
## 3rd Qu.: 1.0000 3rd Qu.: 1.0000
## Max. : 1.0000 Max. : 1.0000
## 87406900 - nitrogenio_total 87406900 - turbidez
## Min. :0.3926 Min. :-0.4238
## 1st Qu.:0.6754 1st Qu.: 1.0000
## Median :0.8658 Median : 1.0000
## Mean :0.8084 Mean : 0.8905
## 3rd Qu.:1.0000 3rd Qu.: 1.0000
## Max. :1.0000 Max. : 1.0000
## 87406900 - nitrogenio_amoniacal 87406900 - pH 87406900 - temperatura_agua
## Min. :0.4212 Min. :0.3926 Min. :-0.3840
## 1st Qu.:0.7397 1st Qu.:1.0000 1st Qu.: 0.4569
## Median :0.8658 Median :1.0000 Median : 0.6015
## Mean :0.8237 Mean :0.8628 Mean : 0.6624
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.: 1.0000
## Max. :1.0000 Max. :1.0000 Max. : 1.0000
## 87406900 - solidos_totais 87406900 - escherichia_coli 87406900 - ano_coleta
## Min. :0.4459 Min. :1 Min. :-0.4238
## 1st Qu.:0.6187 1st Qu.:1 1st Qu.: 1.0000
## Median :0.6958 Median :1 Median : 1.0000
## Mean :0.7839 Mean :1 Mean : 0.8905
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.: 1.0000
## Max. :1.0000 Max. :1 Max. : 1.0000
## 87406900 - condutividade 87409900 - oxigenio_dissolvido 87409900 - dbo
## Min. :0.4024 Min. :1 Min. :0.5624
## 1st Qu.:0.6399 1st Qu.:1 1st Qu.:1.0000
## Median :0.8068 Median :1 Median :1.0000
## Mean :0.7870 Mean :1 Mean :0.9371
## 3rd Qu.:1.0000 3rd Qu.:1 3rd Qu.:1.0000
## Max. :1.0000 Max. :1 Max. :1.0000
## 87409900 - fosforo_total 87409900 - nitrogenio_kjeldahl
## Min. :0.4560 Min. :0.6898
## 1st Qu.:0.8175 1st Qu.:0.9999
## Median :0.8565 Median :1.0000
## Mean :0.8426 Mean :0.9603
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87409900 - nitrogenio_total 87409900 - turbidez
## Min. :0.5245 Min. :0.4405
## 1st Qu.:0.8314 1st Qu.:1.0000
## Median :1.0000 Median :1.0000
## Mean :0.8823 Mean :0.9570
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
## 87409900 - nitrogenio_amoniacal 87409900 - pH 87409900 - temperatura_agua
## Min. :0.7569 Min. :0.4049 Min. :0.4309
## 1st Qu.:0.8915 1st Qu.:1.0000 1st Qu.:1.0000
## Median :1.0000 Median :1.0000 Median :1.0000
## Mean :0.9482 Mean :0.9542 Mean :0.9562
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000
## 87409900 - solidos_totais 87409900 - escherichia_coli 87409900 - ano_coleta
## Min. :0.4405 Min. :0.4528 Min. :0.4528
## 1st Qu.:0.5429 1st Qu.:0.5245 1st Qu.:1.0000
## Median :1.0000 Median :1.0000 Median :1.0000
## Mean :0.8442 Mean :0.8215 Mean :0.9579
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000
## 87409900 - condutividade
## Min. :0.4049
## 1st Qu.:0.4895
## Median :0.7254
## Mean :0.7294
## 3rd Qu.:1.0000
## Max. :1.0000
parametros_IQA %>%
# group_by(codigo) %>%
dplyr::select(
nitrogenio_kjeldahl, condutividade
) %>%
# correlation::cor_test() %>%
plot()Time
for this code chunk to run: 2.73962092399597
(cond_elet <- ggplot(plan_wide_19902020,
aes(codigo,
condutividade))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=500,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.3,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.7,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
facet_wrap(~periodo)+
labs(title = "Condutividade elétrica no período 1990-2020",
x="Estação",
y="µmhos/cm")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$condutividade, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time for
this code chunk to run: 1.33914089202881
(cond_elet_p1 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
condutividade))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=500,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Condutividade elétrica no período 1990-2000",
x="Estação",
y="µmhos/cm")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$condutividade, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.630928039550781
(cond_elet_p2 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010"),
aes(codigo,
condutividade))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=500,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Condutividade elétrica no período 2000-2010",
x="Estação",
y="µmhos/cm")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$condutividade, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.727335929870605
(cond_elet_p3 <- ggplot(plan_wide_19902020 %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020"),
aes(codigo,
condutividade))+
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=500,
ymax=Inf,
alpha=1,
fill="#eb5661")+ #classe 4
annotate("rect",
xmin=-Inf,
xmax=Inf,
ymin=-Inf,
ymax=500,
alpha=1,
fill="#8dcdeb")+ #classe 1
stat_boxplot(geom = 'errorbar',
width=0.3,
position = position_dodge(width = 0.65))+
geom_boxplot(fill='#F8F8FF',
color="black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
width= 0.7)+
labs(title = "Condutividade elétrica no período 2010-2020",
x="Estação",
y="µmhos/cm")+
scale_y_continuous(expand = expansion(mult = c(0.01, 0.05)),
n.breaks = 8,
limits = c(0,
max(plan_wide_19902020$condutividade, na.rm = TRUE)),
labels = scales::number_format(accuracy = 1,
decimal.mark = ",",
big.mark = " "))+
ggbeeswarm::geom_quasirandom(
size = 1.2,
alpha = .25,
width = .07,
)+
scale_x_discrete(limits = c("87398500",
"87398980",
"87398900",
"87398950",
"87405500",
"87406900",
"87409900"),
labels = c("PM1", "PM2", "PM3", "PM4", "PM5", "PM6", "PM7")
)+
geom_smooth(method = "lm",
se=FALSE, #se deixar TRUE gera o intervalo de confiança de 95%
aes(group=1),
alpha=.5,
na.rm = TRUE,
size = 1)+
theme_grafs()
)Time
for this code chunk to run: 0.597105026245117
grid.arrange(cond_elet_p1, cond_elet_p2, cond_elet_p3, ncol = 3)Time
for this code chunk to run: 1.82918095588684
(sum_cond_elet_p1 <- plan_wide_19902020 %>%
select(codigo, condutividade, ano_coleta) %>%
filter(ano_coleta>"1990" &
ano_coleta<="2000") %>%
group_by(codigo) %>%
summarize(
min =
min(condutividade,
na.rm = TRUE),
q1 =
quantile(condutividade, 0.25,
na.rm = TRUE),
median =
median(condutividade,
na.rm = TRUE),
mean =
mean(condutividade,
na.rm= TRUE),
q3 =
quantile(condutividade, 0.75,
na.rm = TRUE),
max =
max(condutividade,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 9.4 51.1 67 75.1 83.2 340
## 2 87398900 10 41.5 51 55.3 64.2 160
## 3 87398950 9 41.5 51.5 60.1 69.5 160
## 4 87398980 11.3 42.4 52.0 53.0 67.0 83.8
## 5 87405500 25 68.7 88.2 130. 170 560
## 6 87406900 52 88.4 133. 193. 256. 576
## 7 87409900 29 80 110. 134. 168. 460
(sum_cond_elet_p2 <- plan_wide_19902020 %>%
select(codigo, condutividade, ano_coleta) %>%
filter(ano_coleta>"2000" &
ano_coleta<="2010") %>%
group_by(codigo) %>%
summarize(
min =
min(condutividade,
na.rm = TRUE),
q1 =
quantile(condutividade, 0.25,
na.rm = TRUE),
median =
median(condutividade,
na.rm = TRUE),
mean =
mean(condutividade,
na.rm= TRUE),
q3 =
quantile(condutividade, 0.75,
na.rm = TRUE),
max =
max(condutividade,
na.rm = TRUE))
)## # A tibble: 7 × 7
## codigo min q1 median mean q3 max
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 87398500 11.9 67.0 82.6 84.8 102. 164.
## 2 87398900 11 44.4 52.3 57.1 72.6 136.
## 3 87398950 39.8 58.4 76 82.3 98.3 160
## 4 87398980 9.4 42.4 49.7 51.5 62 114.
## 5 87405500 17 77.5 107 142. 171. 679
## 6 87406900 23.1 85.6 124. 164. 199. 619
## 7 87409900 56.1 114. 177 200. 242 454
(sum_cond_elet_p3 <- plan_wide_19902020 %>%
select(codigo, condutividade, ano_coleta) %>%
filter(ano_coleta>"2010" &
ano_coleta<="2020") %>%
group_by(codigo) %>%
summarize(
min =
min(condutividade,
na.rm = TRUE),
q1 =
quantile(condutividade, 0.25,
na.rm = TRUE),
median =
median(condutividade,
na.rm = TRUE),
mean =
mean(condutividade,
na.rm= TRUE),
q3 =
quantile(condutividade, 0.75,
na.rm = TRUE),
max =
max(condutividade,
na.rm = TRUE),
n =
length(condutividade))
)## # A tibble: 7 × 8
## codigo min q1 median mean q3 max n
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
## 1 87398500 0.01 68.5 80.2 80.4 99.5 125. 34
## 2 87398900 39.7 53.4 58.3 61.1 65.5 103 36
## 3 87398950 40.9 64.7 70.1 76.1 82.5 195. 35
## 4 87398980 43.2 51.7 54.0 56.3 61.0 78.9 28
## 5 87405500 47 85.8 121. 146. 209. 286 33
## 6 87406900 62.7 95.9 142. 163. 216. 354. 35
## 7 87409900 65.7 121. 159. 179. 245. 498. 37
# plan_wide_19902020 %>%
# select(codigo, IQA) %>%
# group_by(codigo) %>%
# summarize(
# min =
# min(IQA,
# na.rm = TRUE),
# q1 =
# quantile(IQA, 0.25,
# na.rm = TRUE),
# median =
# median(IQA,
# na.rm = TRUE),
# mean =
# mean(IQA,
# na.rm= TRUE),
# q3 =
# quantile(IQA, 0.75,
# na.rm = TRUE),
# max =
# max(IQA,
# na.rm = TRUE))Time for this code chunk to run: 0.204574108123779
ggsave("cond_elet.png",
units = c("px"),
width = 4500,
height = 2993,
plot = cond_elet,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("cond_elet_p1.png",
plot = cond_elet_p1,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("cond_elet_p2.png",
plot = cond_elet_p2,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("cond_elet_p3.png",
plot = cond_elet_p3,
path = "./graficos",
dpi = 300,
type = "cairo")
ggsave("cond_elet_3periodos.png",
units = c("px"),
width = 4500,
height = 2993,
plot = grid.arrange(cond_elet_p1, cond_elet_p2, cond_elet_p3, ncol = 3),
path = "./graficos",
dpi = 300,
type = "cairo")Time
for this code chunk to run: 6.51275515556335
10.8
Os resultados apontam que para o parâmetro OD
set.seed(2023)
exemplo_boxplot_df <- data.frame(
PM = c("PM1"),
# letras = letters[seq( from = 1, to = 1 )],
Stat1 = rnorm(100,
mean = 5,
sd = 1.8)
)
(sumario_exemplo_bp <- exemplo_boxplot_df %>%
group_by(PM) %>%
summarize(
max = max(Stat1),
p95 = quantile(Stat1, 0.95),
p80 = quantile(Stat1, 0.8),
median = median(Stat1),
p20 = quantile(Stat1, 0.2),
p05 = quantile(Stat1, 0.05),
min = min(Stat1),
) %>%
t() %>%
row_to_names(row_number = 1) %>%
as.numeric()
)## [1] 9.923430 7.866927 6.683828 4.886935 3.545771 2.277104 1.282177
(boxplot_example <- exemplo_boxplot_df %>%
ggplot(
aes(
x = PM,
y = Stat1,
)
)+
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.15,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.40,
fill = '#F8F8FF',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
labs(
title = "Elementos do *boxplot*",
x= NULL,
y= NULL
)+
ggbeeswarm::geom_quasirandom(
size = 1.4,
alpha = .3,
width = .07,
)+
scale_y_continuous(
expand = expansion(mult = c(0,0)),
n.breaks = 8,
limits = c(-0.3,12)
)+
annotate(
geom = "text",
x = 1.55,
hjust = "right",
y = sumario_exemplo_bp,
label = c("Valor máximo", "P95", "P80", "Mediana", "P20", "P05", "Valor mínimo"),
# fontface = 3
)+
geom_richtext(
x = 0.56,
y = 9.103998,
label.color = NA,
hjust = "center",
label = "<i>Outliers</i>"
)+
geom_curve(
aes(
x = 0.6, xend = 0.98,
y = 9.103998 , yend = 9.103998 , #Outliers
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
#definindo o [
geom_curve(
aes(
x = 0.74, xend = 0.78,
y = 6.683828, yend = 6.683828,
),
curvature = 0,
size = 1.0,
lineend = "butt"
)+
geom_curve(
aes(
x = 0.74, xend = 0.74,
y = 3.545771, yend = 6.683828,
),
curvature = 0,
size = 1.0,
lineend = "butt"
)+
annotate(
geom = "text",
x = 0.56,
hjust = "center",
y = 5.11,
label = "Amplitude\n(P80-P20)"
)+
geom_curve(
aes(
x = 0.74, xend = 0.78,
y = 3.545771 , yend = 3.545771 ,
),
curvature = 0,
size = 1.0,
lineend = "butt"
)+
# fim do [
geom_curve(
aes(
x = 0.6, xend = 0.90,
y = 7.866927 , yend = 7.866927 , #whisker superior
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
annotate(
geom = "text",
x = 0.56,
hjust = "center",
y = 7.866927,
label = "Whisker\nsuperior"
)+
geom_curve(
aes(
x = 0.6, xend = 0.90,
y = 2.277104 , yend = 2.277104 , #whisker inferior
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
annotate(
geom = "text",
x = 0.56,
hjust = "center",
y = 2.277104,
label = "Whisker\ninferior"
)+
geom_curve(
aes(
x = 1.4, xend = 1.01,
y = 9.92343, yend = 9.92343, #valor máximo
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.45, xend = 1.11,
y = 7.866927 , yend = 7.866927 , #P95
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.45, xend = 1.22,
y = 6.683828 , yend = 6.683828 , #P80
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.45, xend = 1.22,
y = 4.886935 , yend = 4.886935 , #P50
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.45, xend = 1.22,
y = 3.545771, yend = 3.545771, #P20
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.45, xend = 1.11,
y = 2.277104, yend = 2.277104, #P05
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
geom_curve(
aes(
x = 1.4, xend = 1.01,
y = 1.282177, yend = 1.282177, #valor mínimo
),
curvature = 0,
size = 1.0,
arrow = arrow(length = unit(0.05, "npc")),
lineend = "round"
)+
# theme_grafs()+
theme_bw()+
theme(
plot.title =
element_markdown(
hjust = 0.5,
color = "black",
size = 19),
)
)Time
for this code chunk to run: 2.35132479667664
ggsave(
filename = "exemplo_boxplot.png",
plot = boxplot_example,
units = c("px"),
width = (4500)/1.5,
height = (2993)/1.5,
path = "./graficos",
dpi = 300,
# type = "cairo"
)Time for this code chunk to run: 2.47104907035828
set.seed(2021)
data <- tibble(
grupo = factor(
c(rep(
"Grupo 1", 100),
rep("Grupo 2", 250),
rep("Grupo 3", 25)
)
),
valor = c(seq(0, 20, length.out = 100),
c(rep(0, 5),
rnorm(30, 2, .1),
rnorm(90, 5.4, .1),
rnorm(90, 14.6, .1),
rnorm(30, 18, .1),
rep(20, 5)
),
rep(seq(0, 20, length.out = 5), 5))
) %>%
rowwise() %>%
mutate(
valor = if_else(
grupo == "Grupo 2", valor + rnorm(1, 0, .4),
valor
)
)
## function to return median and labels
n_fun <- function(x){
return(
data.frame(
y = median(x) - 1.25,
label = paste0(
"n = ",length(x)
)
)
)
}Time for this code chunk to run: 0.152824878692627
(tukey_n_boxplot <- ggplot(data,
aes(x = grupo,
y = valor)
)+
stat_boxplot(geom = 'errorbar',
width = 0.15,
position = position_dodge(width = 0.65))+
geom_boxplot(fill = "grey92",
width = 0.40,
position = position_dodge(width = 0.65))+
## use summary function to add text labels
stat_summary(
geom = "text",
fun.data = n_fun,
# family = "Oswald",
size = 5
)+
labs(
title = "Tukey *boxplot*",
x= NULL,
# y="mg/L"
)+
# theme_grafs()+
theme_bw()+
theme(
axis.text.y = element_text(
angle = 90,
# size=15,
# face=2
),
plot.title =
element_markdown(
hjust = 0.5,
color = "black",
size = 19)
)
)(tukey_boxplot <- ggplot(data, aes(x = grupo,
y = valor)) +
stat_boxplot(geom = 'errorbar',
width = 0.15,
position = position_dodge(width = 0.65))+
geom_boxplot(fill = "grey92",
width = 0.40,
position = position_dodge(width = 0.65)) +
## use either geom_point() or geom_jitter()
geom_point(
## draw bigger points
size = 2,
## add some transparency
alpha = .25,
## add some jittering
position = position_jitter(
## control randomness and range of jitter
seed = 1, width = .2
)
)+
theme_bw()+
labs(
title = "Tukey *boxplot*",
x= NULL,
# y="mg/L"
)+
# theme_grafs()+
theme_bw()+
theme(
axis.text.y = element_text(
angle = 90,
# size=15,
# face=2
),
plot.title =
element_markdown(
hjust = 0.5,
color = "black",
size = 19)
))Time
for this code chunk to run: 1.10362911224365
data %>%
group_by(grupo) %>%
summarize(
min = min(valor),
P20 = quantile(valor, 0.20),
q1 = quantile(valor, 0.25),
mediana = median(valor),
q3 = quantile(valor, 0.75),
P80 = quantile(valor, 0.80),
max = max(valor)
) %>%
t() %>%
row_to_names(row_number = 1)## Grupo 1 Grupo 2 Grupo 3
## min " 0.0000000" "-0.6345142" " 0.0000000"
## P20 "4.000000" "5.057189" "4.000000"
## q1 "5.000000" "5.245691" "5.000000"
## mediana "10.00000" "10.01593" "10.00000"
## q3 "15.00000" "14.81205" "15.00000"
## P80 "16.00000" "15.04351" "16.00000"
## max "20.0000" "20.3882" "20.0000"
(box_percentile_plot <- ggplot(data,
aes(x = grupo, y = valor)
) +
stat_summary(
fun.data = f,
geom = 'errorbar',
width = 0.15,
position = position_dodge(width = 0.65),
)+
stat_summary(
fun.data = f,
geom = "boxplot",
width = 0.40,
fill = 'grey92',
color = "black",
outlier.shape = NA, #se deixar NA fica só o jitter, se não, deixa 1
)+
# geom_boxplot(fill = "grey92") +
## use either geom_point() or geom_jitter()
geom_point(
## draw bigger points
size = 2,
## add some transparency
alpha = .25,
## add some jittering
position = position_jitter(
## control randomness and range of jitter
seed = 1, width = .2
)
)+
labs(
title = "*Box Percentile-Plot*",
x= NULL,
# y="mg/L"
)+
# theme_grafs()+
theme_bw()+
theme(
axis.text.y = element_text(
angle = 90,
# size = 15,
# face = 2
),
plot.title =
element_markdown(
hjust = 0.5,
color = "black",
size = 19)
)
)grid.arrange(
tukey_boxplot, box_percentile_plot,
ncol = 2
)fig_tukey_garrett <- plot_grid(tukey_boxplot, box_percentile_plot,
labels = "AUTO")Time for this code chunk to run: 2.12748694419861
ggsave(
filename = "tukey_n_boxplot.png",
plot = tukey_n_boxplot,
units = c("px"),
width = 4500,
height = 2993,
path = "./graficos",
dpi = 300,
# type = "cairo"
)
ggsave(
filename = "tukey_boxplot.png",
plot = tukey_boxplot,
units = c("px"),
width = 4500,
height = 2993,
path = "./graficos",
dpi = 300,
# type = "cairo"
)
ggsave(
filename = "box_percentile_plot.png",
plot = box_percentile_plot,
units = c("px"),
width = 4500,
height = 2993,
path = "./graficos",
dpi = 300,
# type = "cairo"
)
ggsave(
filename = "fig_tukey_garrett.png",
plot = fig_tukey_garrett,
units = c("px"),
width = 4500,
height = 2993,
path = "./graficos",
dpi = 300,
# type = "cairo"
)Time for this code chunk to run: 3.09082198143005